package com.netease.research.controller.buyer;

import com.netease.research.Vo.AccountVo;
import com.netease.research.common.Const;
import com.netease.research.common.ServerResponse;
import com.netease.research.common.StatusCode;
import com.netease.research.pojo.Account;
import com.netease.research.pojo.User;
import com.netease.research.service.IAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class AccountController {

    @Autowired
    private IAccountService iAccountService;

    @RequestMapping("create_order.do")
    @ResponseBody
    public ServerResponse<List<AccountVo>> createOrder(HttpSession session){
        User user=(User) session.getAttribute(Const.CURRENT_USER);
        if(user!=null){
            return iAccountService.createOrder(user.getId());
        }
        return ServerResponse.createByCode(StatusCode.NEED_LOGIN.getCode());
    }

    @RequestMapping("list_all_order.do")
    @ResponseBody
    public ServerResponse<List<AccountVo>> listAll(HttpSession session){
        User user=(User)session.getAttribute(Const.CURRENT_USER);
        if(user!=null){
            return iAccountService.listAll(user.getId());
        }
        return ServerResponse.createByCode(StatusCode.NEED_LOGIN.getCode());
    }
}
